package com.eonmind.knowledge.converts;

import com.eonmind.common.provider.entity.knowledge.Knowledge;
import com.eonmind.knowledge.dto.KnowledgeDto;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @Author: AKang
 * @Description:
 * @CreateTime: 2025-05-12
 */
public class KnowledgeConvert {
    public static Knowledge toKnowledge(KnowledgeDto.KnowledgeCreateRequest knowledgeCreateRequest) {
        Knowledge knowledge = new Knowledge();
        BeanUtils.copyProperties(knowledgeCreateRequest, knowledge);
        return knowledge;
    }


    public static Knowledge requestToKnowledge(KnowledgeDto.KnowledgeUpdateRequest knowledgeUpdateRequest) {
        Knowledge knowledge = new Knowledge();
        BeanUtils.copyProperties(knowledgeUpdateRequest, knowledge);
        knowledge.setId(knowledgeUpdateRequest.getKnowledgeId());
        return knowledge;
    }

    public static List<KnowledgeDto.KnowledgeResponse> toKnowledgeResponseList(List<Knowledge> knowledgeList) {
        return knowledgeList.stream().map(KnowledgeConvert::toKnowledgeResponse).toList();
    }

    public static KnowledgeDto.KnowledgeResponse toKnowledgeResponse(Knowledge knowledge) {
        KnowledgeDto.KnowledgeResponse knowledgeResponse = new KnowledgeDto.KnowledgeResponse();
        BeanUtils.copyProperties(knowledge, knowledgeResponse);
        return knowledgeResponse;
    }

    public static List<KnowledgeDto.KnowledgeResponse> toKnowledgePageResponseList(List<Knowledge> list) {
        List<KnowledgeDto.KnowledgeResponse> list1 = list.stream().map(KnowledgeConvert::toKnowledgeResponse).toList();
        return list1;
    }
}
